<script>
    function validate() {
        // Hide all validators
        $('.validator').css('visibility', 'hidden');

        // Check field function
        var checkField = function(name) {
            var fieldValue = $('[name="' + name + '"]').val();
            
            if (fieldValue == '' || fieldValue == null) {
            	$('#' + name + '_validator').css('visibility', 'visible');
            	
                return false;
            }
            
            return true;
        }

        // Check all fields
        var isValid = true;

        isValid &= checkField('first_name'); 
        isValid &= checkField('last_name'); 
        isValid &= checkField('email'); 

        return isValid;
    };
</script>

<?php 
    use Zend\Escaper\Escaper;    

    $escaper = new Escaper('utf-8');
    
    $firstName = $this->customer->getFirstName();
    $lastName = $this->customer->getLastName();
    $email = $this->customer->getEmail();
    
    // Rendering the form
    echo sprintf('<div>%s</div>', $this->translate('complete your customer data', 'user', $this->locale));
        
    echo sprintf('<div>%s</div>', $this->translate('first name', 'user', $this->locale));
    echo sprintf('<input type="text" class="customer" name="first_name" value="%s"></input>', $this->type, $escaper->escapeHtml($firstName));
    echo sprintf('<div class="validator" id="first_name_validator">%s</div>', $this->translate('fill first name', 'user', $this->locale));

    echo sprintf('<div>%s</div>', $this->translate('last name', 'user', $this->locale));
    echo sprintf('<input type="text" class="customer" name="last_name" value="%s"></input>', $this->type, $escaper->escapeHtml($lastName));
    echo sprintf('<div class="validator" id="last_name_validator">%s</div>', $this->translate('fill last name', 'user', $this->locale));

    echo sprintf('<div>%s</div>', $this->translate('email', 'user', $this->locale));
    echo sprintf('<input type="text" class="customer" name="email" value="%s"></input>', $this->type, $escaper->escapeHtml($email));
    echo sprintf('<div class="validator" id="email_validator">%s</div>', $this->translate('fill email', 'user', $this->locale));
    
?>
